package com.burt.user.web.controller;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.burt.user.domain.UserInfo;
import com.burt.user.service.UserService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author luowei1
 * @date 2018/7/17 10:19
 */
@Slf4j
@RestController
public class UserServiceProviderRestApiController {

    private final UserService userService;

    @Autowired
    public UserServiceProviderRestApiController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 保存用户
     * 
     * @param userInfo UserInfo
     * @return 如果保存成功，返回{@link UserInfo 用户信息}，否则返回<code>null</code>
     */
    @PostMapping("/save/user")
    public UserInfo saveUser(@RequestBody UserInfo userInfo) {
        if (userService.saveUser(userInfo)) {
            log.info("保存用户成功:{}", userInfo);
            return userInfo;
        }
        return null;
    }

    /**
     * 查询所有的用户数据
     *
     * @reture 所有的用户数据
     */
    @GetMapping("/find/all")
    public Collection<UserInfo> findAllUser() {
        return userService.findAllUser();
    }

    @GetMapping("/user")
    public UserInfo getUser(String name) {
        System.out.println("name = " + name);
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(1L);
        userInfo.setName(name);
        return userInfo;
    }
}
